package com.dayaokeji.rhythmschoolstudent.client.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.dayaokeji.rhythmschoolstudent.R;
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.BaseActivity;

import butterknife.BindView;

/**
 * 课程历史
 */
public class CourseSearchActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.et_search)
    EditText etSearch;

    private CourseSearchListFragment courseSearchListFragment;

    public static void navigation(Context context) {
        Intent intent = new Intent(context, CourseSearchActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course_search);
        setSupportActionBar(toolbar);

        init();
    }

    private void init() {
        etSearch.addTextChangedListener(textWatcher);
        final FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        courseSearchListFragment = CourseSearchListFragment.newInstance();
        fragmentTransaction.replace(R.id.content, courseSearchListFragment);
        fragmentTransaction.commit();
    }

    private TextWatcher textWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (courseSearchListFragment != null) {
                courseSearchListFragment.queryKeyword(s.toString());
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    };
}
